(define (equal? list1 list2)
  (define (both pred a b)
    (and (pred a) (pred b)))
  (define (is-not p) (lambda (x) (not (p x))))
  ;; Main precedure
  (cond ((both null? list1 list2) #t)
        ((both (is-not null?) list1 list2)
         (let ((head1 (car list1))
               (head2 (car list2)))
           (and (cond ((both pair? head1 head2) (equal? head1 head2))
                      ((both (is-not pair?) head1 head2) (eq? head1 head2))
                      (else #f))
                (equal? (cdr list1) (cdr list2)))))
        (else #f)))
